class Solution {
    public int[] findBall(int[][] grid) {
        int m=grid.length;
        int n=grid[0].length;
        int[] ans=new int[n];
        for(int i=0;i<n;i++){
            int t=i;
            for(int j=0;j<m;j++){
                t+=grid[j][i];
                if(t<0 || t==n || grid[j][i]!=t){
                    break;
                }
            }
            ans[i]=t;
        }
        return ans;
    }
}